# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException

import unittest, time

class Untitled2(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://localhost/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_untitled2(self):
        driver = self.driver
        driver.get(self.base_url + "/php4dvd/")
        driver.find_element_by_id("username").clear()
        driver.find_element_by_id("username").send_keys("admin")
        driver.find_element_by_name("password").clear()
        driver.find_element_by_name("password").send_keys("admin")
        driver.find_element_by_name("submit").click()
        driver.find_element_by_css_selector("img[alt=\"Add movie\"]").click()
        driver.find_element_by_name("name").clear()
        driver.find_element_by_name("name").send_keys("Edge of tomorrow")
        movie_name = movie_year = ""
        movie_name = driver.find_element_by_name("name").get_attribute("value")
        driver.find_element_by_id("submit").click()
        try:
            driver.find_element_by_css_selector("label.error")
        except NoSuchElementException, e:
            return False
        driver.find_element_by_name("year").clear()
        driver.find_element_by_name("year").send_keys("2014")
        movie_year = driver.find_element_by_name("year").get_attribute("value")
        if movie_year != "" and movie_name != "":
            driver.find_element_by_id("submit").click()
        else:
            return False

        try:
            driver.find_element_by_id("movie")
        except NoSuchElementException, e:
            return False

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
